#include "chat.h"
#include <QPainter>
#include <QPen>
#include <QTime>

Chat::Chat(QWidget *parent, Hraci * tabulka)
    : QWidget(parent)
{
    this->tabulka=tabulka;
    chatdata = new QTextEdit();
    chatdata->setReadOnly(true);
    chatradek = new QLineEdit();
    mainLayout = new QVBoxLayout();
    mainLayout->addWidget(chatdata);
    mainLayout->addWidget(chatradek,1,Qt::AlignBottom);
    this->setLayout(mainLayout);
    connect(chatradek, SIGNAL(returnPressed()), this, SLOT(textSent()));
}

void Chat::textSent()
{
    emit newChatMessage(QString("<font color=\"%1\">%2 %3: %4</font>")
                        .arg(tabulka->vratHrace(0)->zjistiBarvu()->name(), QTime::currentTime().toString("H:m:s"),*tabulka->vratHrace(0)->zjistiJmeno(),chatradek->text()));

    chatradek->clear();
}

void Chat::getChatMessage(QString message)
{
    chatdata->append(message);
}
